package peer.dstdb.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;

public class SourceSumMessage2 extends Message{
	public short sType=peer.tools.MessageType.sType_DB_SourceSumMessage2;
	byte[] dpData=null;
	int sourceSum;
	int routePort;
	int tcpPort;
	public SourceSumMessage2(int sourceSum,int routePort,int tcpPort){
		dpData=new byte[16];
		this.sourceSum=sourceSum;
		this.routePort=routePort;
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		ByteIntSwitch.toByteArray(sourceSum, dpData, 4);
		ByteIntSwitch.toByteArray(routePort, dpData, 8);
		ByteIntSwitch.toByteArray(tcpPort, dpData, 12);
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public SourceSumMessage2(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		sourceSum=ByteIntSwitch.toInt(dpData, 4);
		routePort=ByteIntSwitch.toInt(dpData, 8);
		tcpPort=ByteIntSwitch.toInt(dpData, 12);
	}
	
	public int getSourceSum(){
		return sourceSum;
	}
	
	public int getRoutePort(){
		return routePort;
	}
	
	public int getTcpPort(){
		return tcpPort;
	}
}
